<?php

namespace App\Http\Controllers;

use App\Exceptions\BusinessException;
use App\Models\Camp;
use App\Models\Order;
use App\Services\BannerService;
use App\Services\BusService;
use App\Services\CampService;
use App\Services\ComboService;
use App\Services\CompanyService;
use App\Services\ParkService;
use App\Services\SceneService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CampController extends Controller
{
    /**
     * 首页
     * @return JsonResponse
     */
    public function index(Request $request)
    {
        $uid = $request->uid;
        // banner
        $data['banner_list'] = BannerService::getInstance()->list(4, 0);
        // 天气
        $data['weather_info'] = CampService::getInstance()->weatherInfo(510181);
        // 待支付订单
        $data['wait_pay_order_num'] = Order::query()->where(['user_id' => $uid, 'state' => Order::STATE_WAIT_PAY])->count('id');
        // 待使用订单
        $data['wait_use_order_num'] = Order::query()->where(['user_id' => $uid, 'state' => Order::STATE_WAIT_USE])->count('id');
        // 热门套餐
        $data['combo_list'] = ComboService::getInstance()->list(1, 9)['list'];
        // 园区日志
        $data['scene_list'] = SceneService::getInstance()->list(1, 4)['list'];
        // 营地信息
        $data['camp_info'] = Camp::query()->first(['id', 'camp_name', 'camp_tel', 'camp_qrcode', 'lng', 'lat', 'eat_name', 'eat_lng', 'eat_lat']);
        $data['camp_info']['camp_qrcode'] = storage($data['camp_info']['camp_qrcode']);
        return $this->success($data);
    }

    /**
     * 营地详情
     * @return JsonResponse
     */
    public function detail()
    {
        $data = CampService::getInstance()->detail();
        return $this->success($data);
    }

    /**
     * 公司信息
     * @return JsonResponse
     * @throws BusinessException
     */
    public function companyInfo()
    {
        $data = CompanyService::getInstance()->info();
        return $this->success($data);
    }

    /**
     * 公交列表
     * @return JsonResponse
     */
    public function busList()
    {
        $data = BusService::getInstance()->list();
        return $this->success($data);
    }

    /**
     * 停车场列表
     * @return JsonResponse
     */
    public function parkList()
    {
        $data = ParkService::getInstance()->list();
        return $this->success($data);
    }
}
